//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import { SemesterPageRes, SemesterParams, BasePageQuery } from './type'
import { OptionType } from '../user/type'

// 项目用户相关的请求地址
enum Semester_API {
  GET_SEMESTER_PAGE = '/teaching_system/semester/more',
  POST_PUT_SEMESTER_ONE = '/teaching_system/semester/one',
  DELETE_SEMESTER_BYID = '/teaching_system/semester/one/{id}',
  GET_SEMESTER_OPTION = '/teaching_system/semester/option',
}

/**
 * 获取学期分页
 * @param {string} basePageQuery
 * @returns
 */
export const reqGetSemesterPage = (params: BasePageQuery) =>
  request.get<any, AxiosResponse<SemesterPageRes>>(
    Semester_API.GET_SEMESTER_PAGE + '?' + qs.stringify(params),
  )

/**
 * 添加学期
 * @param {object} params 新增学期表
 * @param {string} params.name 名称
 * @param {object} params.startTime 开学时间
 * @param {number} params.weekNum 学期周数
 * @returns
 */
export const reqAddSemester = (params: SemesterParams) =>
  request.post<any, AxiosResponse<any>>(
    Semester_API.POST_PUT_SEMESTER_ONE,
    params,
  )

/**
 * 修改学期
 * @param {object} params 新增学期表
 * @param {number} params.id id
 * @param {string} params.name 名称
 * @param {object} params.startTime 开学时间
 * @param {number} params.weekNum 学期周数
 * @returns
 */
export const reqUpdateSemester = (params: SemesterParams) =>
  request.put<any, AxiosResponse<any>>(
    Semester_API.POST_PUT_SEMESTER_ONE,
    params,
  )

/**
 * 根据id删除学期
 * @param {string} id
 * @returns
 */
export const reqDeleteSemesterById = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    Semester_API.DELETE_SEMESTER_BYID.replace('{id}', id.toString()),
  )

/**
 * 获取学期选项
 * @returns
 */
export const reqGetSemesterOption = () =>
  request.get<any, AxiosResponse<OptionType[]>>(
    Semester_API.GET_SEMESTER_OPTION,
  )
